home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / POV-Ray 3.0.2 / src / SOURCE / ray.c < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-18  |  5.4 KB  |  282 lines  |  [TEXT/MPS ]

  1. /****************************************************************************
  2. *                ray.c
  3. *
  4. *  This module implements the code pertaining to rays.
  5. *
  6. *  from Persistence of Vision(tm) Ray Tracer
  7. *  Copyright 1996 Persistence of Vision Team
  8. *---------------------------------------------------------------------------
  9. *  NOTICE: This source code file is provided so that users may experiment
  10. *  with enhancements to POV-Ray and to port the software to platforms other 
  11. *  than those supported by the POV-Ray Team.  There are strict rules under
  12. *  which you are permitted to use this file.  The rules are in the file
  13. *  named POVLEGAL.DOC which should be distributed with this file. If 
  14. *  POVLEGAL.DOC is not available or for more info please contact the POV-Ray
  15. *  Team Coordinator by leaving a message in CompuServe's Graphics Developer's
  16. *  Forum.  The latest version of POV-Ray may be found there as well.
  17. *
  18. * This program is based on the popular DKB raytracer version 2.12.
  19. * DKBTrace was originally written by David K. Buck.
  20. * DKBTrace Ver 2.0-2.12 were written by David K. Buck & Aaron A. Collins.
  21. *
  22. *****************************************************************************/
  23.  
  24. #include "frame.h"
  25. #include "vector.h"
  26. #include "povproto.h"
  27. #include "povray.h"
  28. #include "ray.h"
  29. #include "texture.h"
  30.  
  31.  
  32.  
  33. /*****************************************************************************
  34. * Local preprocessor defines
  35. ******************************************************************************/
  36.  
  37.  
  38.  
  39. /*****************************************************************************
  40. * Local typedefs
  41. ******************************************************************************/
  42.  
  43.  
  44.  
  45. /*****************************************************************************
  46. * Local variables
  47. ******************************************************************************/
  48.  
  49.  
  50.  
  51. /*****************************************************************************
  52. * Static functions
  53. ******************************************************************************/
  54.  
  55.  
  56.  
  57. /*****************************************************************************
  58. *
  59. * FUNCTION
  60. *
  61. *   Initialize_Ray_Containers
  62. *
  63. * INPUT
  64. *   
  65. * OUTPUT
  66. *   
  67. * RETURNS
  68. *   
  69. * AUTHOR
  70. *
  71. *   POV-Ray Team
  72. *   
  73. * DESCRIPTION
  74. *
  75. *   -
  76. *
  77. * CHANGES
  78. *
  79. *   -
  80. *
  81. ******************************************************************************/
  82.  
  83. void Initialize_Ray_Containers(Ray)
  84. RAY *Ray;
  85. {
  86.   Ray->Containing_Index = - 1;
  87. }
  88.  
  89.  
  90.  
  91. /*****************************************************************************
  92. *
  93. * FUNCTION
  94. *
  95. *   Copy_Ray_Containers
  96. *
  97. * INPUT
  98. *   
  99. * OUTPUT
  100. *   
  101. * RETURNS
  102. *   
  103. * AUTHOR
  104. *
  105. *   POV-Ray Team
  106. *
  107. * DESCRIPTION
  108. *
  109. *   -
  110. *
  111. * CHANGES
  112. *
  113. *   -
  114. *
  115. ******************************************************************************/
  116.  
  117. void Copy_Ray_Containers(Dest_Ray, Source_Ray)
  118. RAY *Dest_Ray, *Source_Ray;
  119. {
  120.   register int i;
  121.  
  122.   Dest_Ray->Containing_Index = Source_Ray->Containing_Index;
  123.  
  124.   for (i = 0 ; i <= Source_Ray->Containing_Index; i++)
  125.   {
  126.     Dest_Ray->Containing_Textures[i] = Source_Ray->Containing_Textures[i];
  127.     Dest_Ray->Containing_Objects[i]  = Source_Ray->Containing_Objects[i];
  128.     Dest_Ray->Containing_IORs[i]     = Source_Ray->Containing_IORs[i];
  129.   }
  130. }
  131.  
  132.  
  133.  
  134. /*****************************************************************************
  135. *
  136. * FUNCTION
  137. *
  138. *   Ray_Enter
  139. *
  140. * INPUT
  141. *   
  142. * OUTPUT
  143. *   
  144. * RETURNS
  145. *   
  146. * AUTHOR
  147. *
  148. *   POV-Ray Team
  149. *   
  150. * DESCRIPTION
  151. *
  152. *   -
  153. *
  154. * CHANGES
  155. *
  156. *   Oct 1995 : Fixed bug with IOR assignment (only valid for plain textures) [DB]
  157. *
  158. ******************************************************************************/
  159.  
  160. void Ray_Enter(Ray, texture, object)
  161. RAY *Ray;
  162. TEXTURE *texture;
  163. OBJECT *object;
  164. {
  165.   register int index;
  166.  
  167.   if ((index = ++(Ray->Containing_Index)) >= MAX_CONTAINING_OBJECTS)
  168.   {
  169.     Error("Too many nested refracting objects.");
  170.   }
  171.  
  172.   Ray->Containing_Textures[index] = texture;
  173.  
  174.   if ((texture->Type == PLAIN_PATTERN) && (texture->Finish != NULL))
  175.   {
  176.     Ray->Containing_IORs[index] = texture->Finish->Index_Of_Refraction;
  177.   }
  178.   else
  179.   {
  180.     Ray->Containing_IORs[index] = Frame.Atmosphere_IOR;
  181.   }
  182.  
  183.   Ray->Containing_Objects[index] = object;
  184. }
  185.  
  186.  
  187.  
  188. /*****************************************************************************
  189. *
  190. * FUNCTION
  191. *
  192. *   Ray_Exit
  193. *
  194. * INPUT
  195. *   
  196. * OUTPUT
  197. *   
  198. * RETURNS
  199. *   
  200. * AUTHOR
  201. *
  202. *   POV-Ray Team
  203. *   
  204. * DESCRIPTION
  205. *
  206. *   Remove given entry from given ray's container.
  207. *
  208. * CHANGES
  209. *
  210. *   -
  211. *
  212. ******************************************************************************/
  213.  
  214. void Ray_Exit(Ray, nr)
  215. RAY *Ray;
  216. int nr;
  217. {
  218.   int i;
  219.  
  220.   for (i = nr; i < Ray->Containing_Index; i++)
  221.   {
  222.     Ray->Containing_Textures[i] = Ray->Containing_Textures[i+1];
  223.     Ray->Containing_Objects[i]  = Ray->Containing_Objects[i+1];
  224.     Ray->Containing_IORs[i]     = Ray->Containing_IORs[i+1];
  225.   }
  226.  
  227.   if (--(Ray->Containing_Index) < - 1)
  228.   {
  229.     Error("Too many exits from refractions.");
  230.   }
  231. }
  232.  
  233.  
  234.  
  235. /*****************************************************************************
  236. *
  237. * FUNCTION
  238. *
  239. *   Texture_In_Ray_Container
  240. *
  241. * INPUT
  242. *
  243. * OUTPUT
  244. *
  245. * RETURNS
  246. *
  247. * AUTHOR
  248. *
  249. *   Dieter Bayer
  250. *
  251. * DESCRIPTION
  252. *
  253. *   Test if a given texture is in the container of a given ray.
  254. *
  255. * CHANGES
  256. *
  257. *   Mar 1996 : Creation.
  258. *
  259. ******************************************************************************/
  260.  
  261. int Texture_In_Ray_Container(Ray, Texture)
  262. RAY *Ray;
  263. TEXTURE *Texture;
  264. {
  265.   int i, found;
  266.  
  267.   found = -1;
  268.  
  269.   for (i = 0; i <= Ray->Containing_Index; i++)
  270.   {
  271.     if (Texture == Ray->Containing_Textures[i])
  272.     {
  273.       found = i;
  274.  
  275.       break;
  276.     }
  277.   }
  278.  
  279.   return(found);
  280. }
  281.  
  282.